package com.xpgk.mvc.ddc.statistic.mdStatistic.mdYearStatistic;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.ddc.statistic.mdStatistic.mdMonthStatistic.MdMonthStasticSQL;
import com.xpgk.mvc.ddc.statistic.mdStatistic.mdMonthStatistic.MdMonthStasticXLS;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.user.User;

public class MdYearStasticController extends BaseController{

	public void index(){
		Organization org = Organization.dao.findById(getCUserOrganIds());
		setAttr("curOrgan", org);
		render("mdYearStastic.html");
	}
	
	public void getList(){
		String organIds = getPara("organIds");
		String sql = getSqlMy(MdYearStasticSQL.sqlId_splitPageFrom);
		List<Record> result = Db.find(sql,organIds);
		renderJson(result);
	}
	
	public   void  excel() 
	{
		int zcgd = 0;
		int zygd = 0;
		int bggd = 0;
		int bhpgd = 0;
		int bzjgd = 0;
		int zxgd = 0;
		User user = User.dao.findById(getCUserIds());
		Organization org = Organization.dao.findById(getCUserOrganIds());
		String organIds = getPara("organIds");
		String sql = getSqlMy(MdYearStasticSQL.sqlId_splitPageFrom);
		List<Record> result = Db.find(sql,organIds);
		renderJson(result);
		if(result!=null && result.size()>0){
			for(Record record:result){
				if(record.getBigDecimal("zcgd")!=null && !record.getBigDecimal("zcgd").equals("")){
					zcgd = zcgd+record.getBigDecimal("zcgd").intValue();
				}
				if(record.getBigDecimal("zygd")!=null && !record.getBigDecimal("zygd").equals("")){
					zygd = zygd+record.getBigDecimal("zygd").intValue();
				}
				if(record.getBigDecimal("bggd")!=null && !record.getBigDecimal("bggd").equals("")){
					bggd = bggd+record.getBigDecimal("bggd").intValue();
				}
				if(record.getBigDecimal("bhpgd")!=null && !record.getBigDecimal("bhpgd").equals("")){
					bhpgd = bhpgd+record.getBigDecimal("bhpgd").intValue();
				}
				if(record.getBigDecimal("bzjgd")!=null && !record.getBigDecimal("bzjgd").equals("")){
					bzjgd = bzjgd+record.getBigDecimal("bzjgd").intValue();
				}
				if(record.getBigDecimal("zxgd")!=null && !record.getBigDecimal("zxgd").equals("")){
					zxgd = zxgd+record.getBigDecimal("zxgd").intValue();
				}
			}
		}
		Record r = new Record();
		r.set("bussdate","合计")
		.set("zcgd",zcgd)
		.set("zygd",zygd)
		.set("bggd",bggd)
		.set("bhpgd",bhpgd)
		.set("bzjgd",bzjgd)
		.set("zxgd",zxgd);
		result.add(r);
		//搜索条件字符串
		String  search="导出人："+user.getStr(User.column_name)+" 导出机构："+org.getStr(Organization.column_name);
		render(new MdYearStasticXLS(result,search,org.getStr(Organization.column_name)+"各年报表"));
	}
}
